package com.core;

import java.util.Random;

import com.core.config.TestConfig;

/**
 * a星测试辅助工具类
 * @author hongxiao.zhuang
 * @date 2013-6-8
 */
public class MapRelated 
{
	public static Random random = new Random();
	/**
	 * 构造一个宽度为width, 高度为height的地图
	 * @param width			地图宽度
	 * @param height		高度
	 * @return				返回地图数据列表
	 * @create 2013-6-8 庄宏晓
	 */
	private static char[][]  paintingMap(int height, int width)
	{
		char[][] str = new char[height][width];
		
		for (int i = 0; i < str.length; i++) 
		{
			for (int j = 0; j < str[i].length; j++) 
			{
				str[i][j] = TestConfig.AIRCHAR;
			}
		}
		
		return str;
	}
	
	/**
	 * 构造一个宽度为width, 高度为height, 并且带有期望数量的随机阻挡的地图
	 * @param width	地图宽度
	 * @param height	地图高度
	 * @param randomSize	随机阻挡的数量(期望数据, 当随机重复时则该数量会减少)
	 * @return				带有阻挡的地图
	 * @create 2013-6-8 庄宏晓
	 */
	public static char[][] paintingRandomStopMap(int height, int width, int randomSize, int startX, int startY, int endX, int endY)
	{
		char[][] str = paintingMap(height, width);
		
		str[startY][startX] = TestConfig.START;
		str[endY][endX] = TestConfig.END;
		
		for (int i = 0; i < randomSize; i++) 
		{
			int indexHeight = random.nextInt(str.length);
			int indexWidth = random.nextInt(str[indexHeight].length);
			
			if(indexWidth == 0 && indexHeight == 0)
			{
				continue;
			}
			
			if(indexHeight == str.length - 1 && indexWidth == str[str.length - 1].length - 1)
			{
				continue;
			}
			
			if(str[indexHeight][indexWidth] == TestConfig.AIRCHAR)
			{
				str[indexHeight][indexWidth] = TestConfig.STOPCHAR;
			}
		}
		
		return str;
	}
	
	/**
	 * 地图输出
	 * @param str
	 * @create 2013-6-8 庄宏晓
	 */
	public static void outputMap(char[][] str)
	{
		for (int i = 0; i < str.length; i++) 
		{
//			System.out.print(i+1 + "\t");
			for (int j = 0; j < str[i].length; j++) 
			{
				System.out.print(str[i][j]);
			}
			
			System.out.println();
		}
		System.out.println(">>>>>>>>>>>>>>>>>>> \n");
	}
}
